﻿using System;
using System.IO;
using visinia.SmartEngine;
using visinia.SmartEngine.Site;

namespace visinia.web.admin.pages
{
    public partial class AdminSiteSettings : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
                return;
            WEBSITE_NAME.Text = SiteSettings.WebsiteName;
            WEBSITE_TAGLINE.Text = SiteSettings.WebsiteTagLine;
            string path = Server.MapPath(WebRoots.GetAdminRoot + "Themes");
            string[] dirs = Directory.GetFileSystemEntries(path);
            foreach (string dir in dirs)
            {
                if (File.Exists(dir + "/admin.master"))
                    ADMIN_THEMES.Items.Add(Path.GetFileName(dir));
            }
            ADMIN_THEMES.SelectedValue = SiteSettings.AdminTheme;
        }

        public void Save()
        {
            SiteSettings.WebsiteName = WEBSITE_NAME.Text;
            SiteSettings.WebsiteTagLine = WEBSITE_TAGLINE.Text;
            SiteSettings.AdminTheme = ADMIN_THEMES.SelectedValue;
            if (REFRESH_SYSTEM_MENU.Checked)
                SystemMenu.RefreshMenus();
            Response.Redirect(Request.RawUrl);
        }
    }
}